from math import sqrt
from itertools import count

def polygonal(s):
    """ Generates all s-gonal numbers.
    I.e.: s=3 for triangonal numbers, 5 for pentagonal, etc.
    """
    for n in count(1):
        yield ((s - 2) * n**2 - (s - 4) * n) / 2    

def triangonal():
    """ Generates all triangonal numbers.
    Triangonal numbers are generated according to the formula n * (n + 1) / 2.
    """
    polygonal(3)


def pentagonal():
    """ Generates all pentagonal numbers.
    Pentagonal numbers are generated according to the formula n * (3 * n - 1) / 2.
    """
    polygonal(5)
        
def isPentagonal(n):
    """ Checks if a number is pentagonal.
    Pentagonal numbers are generated according to the formula n * (3 * n - 1) / 2.
    """
    x = (1.0 + sqrt(1 + 24*n)) / 6
    return int(x) == x
                                
def hexagonal():
    """ Generates all hexanoganl numbers.
    Hexagonal numbers are generated according to the formula n * (2 * n - 1)
    """
    polygonal(6)
  
def isPalindrome(k):
    """ Checks if a number is a palindrome."""
    kstr = str(k)
    lstr = kstr[::-1]
    return kstr == lstr
